<?php

namespace Analysis\Model;

use Think\Model;

class SalestaffModel extends Model
{
    protected $_validate = array(
        array('ssa_status', 'checkReturnVal', '请选择正确的状态类型', 0, 'callback'),
    );
    protected $_auto = array(
        array("ssa_status", "checkstatus", 3, "callback"),
        array('sag_time', 'time', 3, 'function'),
    );

    protected function checkReturnVal($data)
    {
        return $data == 0 ? false : true;
    }

    protected function checkstatus($data)
    {
        $salestaff = M("salestaff");
        $disisbn = M("disisbn");

        $info = $salestaff->where("ssa_id=" . I("get.id"))->find();
        $dis = $disisbn->where("dis_ssaid=" . $info['ssa_id'])->find();
        if ($info["sag_status"] == 8) {
            $str = "你好！你的优惠码编号是" . $dis["dis_isbn"] . "，绑定姓名为" . $info["ssa_name"] . "，绑定手机号码为" . $info["ssa_phone"];
            $val = $data == 1 ? $str : "抱歉，您的信息没有备案，无法通过审批，请尽快与公司销售部联系";
            $info = D('Textchel')->getSmsParam($info["sag_phone"], $val);
        }
        return $data;
    }
}
